#ifndef BASICCONFIG_H_
#define BASICCONFIG_H_



#include <QtCore>
#include <QtPlugin>
#include <QtGui>
#include <QtGui>
#include <QtCore>
#include <QWidget>
#include <QSound>
#include <QSqlDatabase>
#include <QSqlError>
#include <QPair>
#include <QSqlTableModel>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlField>
#include <QTextDocument>
#include <QSqlTableModel>
#include <QSqlRelationalTableModel>
#include <QPair>
#include <QMap>
#include <QDateTime>
#include <QSvgRenderer>
#include <QWidget>
#include <QNetworkInterface>
#include <QFile>
#include <QtCore> 
#include <QCoreApplication>
#include <QDebug>
#include <QSqlQueryModel>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <QInputDialog>
#include <QMenu>
#include <QString>
#include <QtDebug>
#include <QDebug> 
#include <QDesktopServices>
#include <QDebug>
#include <QString>
#include <QMap>
#include <QList>
#include <QStringList>
#include <QObject>
#include <QDateTime>
#include <QDate>
#include <QImageReader>
#include <QPixmap>
#include <QSettings>
#include <QTimer>
#include <QProgressDialog>
#include <QPainter>
#include <QPixmap>
#include <QUrl>
#include <QColorDialog>
#include <QMessageBox>
#include <QWorkspace>
#include <QNetworkInterface>
#include <QDomDocument>
#include <QtDebug>
#include <QDebug> 
#include <QSettings>
#include <QDomDocument>
#include <QDomElement>
#include <QDomImplementation>
#include <QDomProcessingInstruction>
#include <QFile>
#include <QTextCodec>
#include <QString>
#include <QTextDocument>
#include <QTextCursor>
#include <QTextBrowser>
#include <QTextBlockFormat>
#include <QTextFrame>
#include <QTextTable>
#include <QSvgRenderer>

#include <QProcess>
#include <QColor>
#include <QPixmap>
#include <QPainter>
#include <QObject>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#if defined Q_WS_WIN
#include <windows.h>
#if defined VISUALSTUDIOCC_
#include <ddeml.h>
#endif
#endif
#include <QtCore>
#include <QSettings>
#include <QApplication>

#include "pics_structure.h"


#define _DESCI_APP_NAME_ \
         QString( "House Manager")
#define _PROGRAM_NAME_ \
         QString( "House Manager di Vallemaggia Turismo")



#define _NR_ICONE_ATTRIBUTI_ 10

#define _MAX_IMAGE_WIDTH_ 400   /* from  image on board !!!! */
#define MAXUPLOADKILO 2563243


#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif













/* time null unix time long nummer */
static inline uint QTime_Null()
{
    QDateTime timer1( QDateTime::currentDateTime() ); 
    return timer1.toTime_t();
}




/* encode to name */
static inline QString encodeBase64( QString xml )
{
    QByteArray text;
    text.append(xml);
    return text.toBase64();
}

/* decode to name */
static inline QString decodeBase64( QString xml )
{
    QByteArray xcode("");;
    xcode.append(xml);
    QByteArray precode(QByteArray::fromBase64(xcode));
    QString notetxt = precode.data();
    return notetxt;
}





/* quote and dequote sql s result */
static inline QString G_Quote( QString xml )
{
   //the following checks are necessary before exporting
  //strings to XML. see http://hdf.ncsa.uiuc.edu/HDF5/XML/xml_escape_chars.html for details
   QString text = xml;
   text.replace("\"","\\\"");  /* 228 ``*/
   text.replace("'","`");
   return text;
}

static inline QString G_DeQuote( QString xml )
{
   //the following checks are necessary before exporting
  //strings to XML. see http://hdf.ncsa.uiuc.edu/HDF5/XML/xml_escape_chars.html for details
  QString text = xml;
   text.replace("\\\"","\"");  /* 228 ``*/
   text.replace("`","\'");
  return text;
}




static inline QString DateUnix( const uint etime )
{
    QDateTime start = QDateTime::currentDateTime();
    start.setTime_t( etime );
    if (start.toString("HH:mm") == "00:00") {
        return start.toString("dd.MM.yyyy");
    } else {
        return start.toString("dd.MM.yyyy HH:mm");
    }  
}

static inline QString SimpleMonat( const uint etime )
{
    QDateTime start = QDateTime::currentDateTime();
    start.setTime_t( etime );
    return start.toString("dd.MM.");
}



/* return int value from a unixtime date MMM YYY ... */
static inline int dateswap(QString form, uint unixtime )
{
     QDateTime fromunix;
     fromunix.setTime_t(unixtime); 
     QString numeric = fromunix.toString((const QString)form);
     bool ok; 
     return (int)numeric.toFloat(&ok);
}  

 
     
/* display a mail date format  UmanTimeFromUnix(QTime_Null())   */
static inline QString UmanTimeFromUnix( uint unixtime )
{
     /* mail rtf Date format! http://www.faqs.org/rfcs/rfc788.html */
     QDateTime fromunix;
     fromunix.setTime_t(unixtime); 
     QStringList RTFdays = QStringList() << "day_NULL" << "Mon" << "Tue" << "Wed" << "Thu" << "Fri" << "Sat" << "Sun";
     QStringList RTFmonth = QStringList() << "month_NULL" << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
     QDate timeroad(dateswap("yyyy",unixtime),dateswap("M",unixtime),dateswap("d",unixtime));
     /*qDebug() << "### RTFdays " << RTFdays.at(timeroad.dayOfWeek());
     qDebug() << "### RTFmonth " << RTFmonth.at(dateswap("M",unixtime));
     qDebug() << "### yyyy " << dateswap("yyyy",unixtime);
     qDebug() << "### M " << dateswap("M",unixtime);
     qDebug() << "### d " << dateswap("d",unixtime);*/
     QStringList rtfd_line;
     rtfd_line.clear();
     rtfd_line.append("Date: ");
     rtfd_line.append(RTFdays.at(timeroad.dayOfWeek()));
     rtfd_line.append(", ");
     rtfd_line.append(QString::number(dateswap("d",unixtime)));
     rtfd_line.append(" ");
     rtfd_line.append(RTFmonth.at(dateswap("M",unixtime)));
     rtfd_line.append(" ");
     rtfd_line.append(QString::number(dateswap("yyyy",unixtime)));
     rtfd_line.append(" ");
     rtfd_line.append(fromunix.toString("hh:mm:ss"));
     rtfd_line.append("");
     /*qDebug() << "### mail rtf Date format " << rtfd_line.join("");*/
return QString(rtfd_line.join(""));
}
 
 
 static inline QString MailTimeNow() {
    
    return UmanTimeFromUnix( QTime_Null() );
}
 







/* encode to name */
static inline QString EBase64( QString xml )
{
    QByteArray text;
    text.append(xml);
    return text.toBase64();
}

/* decode to name */
static inline QString DBase64( QString xml )
{
    QByteArray xcode("");;
    xcode.append(xml);
    QByteArray precode(QByteArray::fromBase64(xcode));
    QString notetxt = precode.data();
    return notetxt;
}



















#endif /*BASICCONFIG_H_*/
